<template>
  <div class="touzilist">
    <el-card>
      <el-row>
        <el-table :data="tableData.slice((currentPage-1)*pagesize,currentPage*pagesize)" style="width: 100%" border>
          <el-table-column :index="indexMethod" type="index" label="序号" width="50"></el-table-column>
          <el-table-column label="课程名称" align="center" width="200">
            <template slot-scope="scope">
              <span>{{ scope.row.cname}}</span>
            </template>
          </el-table-column>
          <el-table-column label="课程图片" align="center" width="200">
            <template slot-scope="scope">
          <span v-if="scope.row.img == null || scope.row.img === ''">
            <el-image
              class="table-td-thumb"
              style="width: 80px; height: 80px"
              src="http://localhost:8080/CourseHead/zwtp.png"
            ></el-image>
          </span>
              <span v-else>
            <el-image
              class="table-td-thumb"
              style="width: 80px; height: 80px"
              :src="scope.row.img"
              :preview-src-list="[scope.row.img]"
            ></el-image>
          </span>
            </template>
          </el-table-column>
          <el-table-column label="购买时间" align="center" width="200">
            <template slot-scope="scope">
              <span style="color:rgb(0, 208, 83)">{{scope.row.cdate  | dataFormat}}</span>
            </template>
          </el-table-column>
          <el-table-column label="课程类型" align="center" width="180">
            <template slot-scope="scope">
              <span v-if=" scope.row.level==='1'">专升本课程</span>
              <span v-else-if="scope.row.level==='2'">高升本课程</span>
              <span v-else>高升专课程</span>
            </template>
          </el-table-column>
          <el-table-column label="面向类型" align="center" width="180">
            <template slot-scope="scope">
              <span v-if="scope.row.cway=='1'">函授类型</span>
              <span v-else>业余类型</span>
            </template>
          </el-table-column>
          <el-table-column label="课程介绍" align="center" width="205">
            <template slot-scope="scope">
              <span>{{scope.row.cintro}}</span>
            </template>
          </el-table-column>
        </el-table>
      </el-row>
      <!--分页组件-->
      <div style="text-align: center;margin-top: 30px;">
        <el-pagination
          background
          layout="prev, pager, next"
          :page-size="pagesize"
          :total="total"
          :current-page="currentPage"
          @current-change="current_change">
        </el-pagination>
      </div>
    </el-card>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        tableData: [],
        total: 0,
        pagesize: 4,
        currentPage:1,
        dialogTableVisible: false,
        formData: []
      };
    },
    methods: {
      current_change(val){
        this.currentPage = val;
        console.log(val);
        console.log(this.currentPage);
        // console.log(this.tableData);
      },
      getTabsList() {
        this.$axios
          .get("/getStudentCourse", {
            params:{
              sid: sessionStorage.getItem("uid")
            }
          })
          .then(res => {
            //			console.log(res)
            const data = res.data;
            this.tableData = data.data;
            this.total = res.data.data.length;
            console.log(this.tableData)
          });
      },

      indexMethod(index){
        return (this.currentPage-1)*this.pagesize+index+1;
      }
    },
    mounted() {
      this.getTabsList();
    },
  }
</script>

<style scoped>
  .touzilist {
    margin: 10px;
  }
  .elrow{
    margin-bottom: 20px;
  }
</style>
